namespace PickGold.Charting
{
    using System;
    using System.Security.Permissions;
    using System.Web;

    [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    public class ChartAreaCollection : ChartNamedElementCollection<ChartArea>
    {
        internal ChartAreaCollection(ChartPicture chartPicture) : base(chartPicture)
        {
        }

        public ChartArea Add(string name)
        {
            ChartArea item = new ChartArea(name);
            base.Add(item);
            return item;
        }

        internal void ChartAreaNameReferenceChanged(object sender, NameReferenceChangedEventArgs e)
        {
            foreach (ChartArea area in this)
            {
                if (area.AlignWithChartArea == e.OldName)
                {
                    area.AlignWithChartArea = e.NewName;
                }
            }
        }

        internal string DefaultNameReference
        {
            get
            {
                if (base.Count <= 0)
                {
                    return string.Empty;
                }
                return base[0].Name;
            }
        }
    }
}

